import { colourBlend } from "../../utils/index"

let points = [
  0.2, 0.4, 0.2,
  0.4, 0.6, 0.4,
  0.2, 0.4, 0.2,
]

export default function (pxs, main) {
  if (pxs.length == 0) return;
  let _graphics = main.previewContainer.children[0];
  let _pxs = [];
  let row = 3;
  for (let i = 0; i < row; i++) {
    for (let j = 0; j < row; j++) {
      _pxs.push({
        x: pxs[0].x + i - ~~(row / 2),
        y: pxs[0].y + j - ~~(row / 2),
        alpha: points[i * row + j]
      })
    }
  }
  _pxs.forEach(px => {
    const {x, y, alpha} = px;
    _graphics.beginFill(0x000000, alpha);
    _graphics.drawRect(x, y, 1, 1);
    _graphics.endFill();
  })

  if (!main.isUp && main.eventName == "pointerMove" || main.eventName == "pointerDown") {
    main.pxMap.forEach(px => {
      let p = _pxs.find(p => p.x == px.x && p.y == px.y);
      if (p) {
        if (p.alpha == 0) return;
        px.color = colourBlend(px.color || "0xFFFFFF", main.pointColor, (px.alpha + p.alpha) / 2);
        px.alpha = 1;
      }
    })
    main.drawGraphics();
  }
}

